import { ChunkEntityType, ChunkEntityUpdateType } from "../../GameDef";
import { ECSScene } from "../../lib/kgame/ecs/ECSScene";
import { IVec2 } from "../../lib/kgame/util/Defined";
import { CmpChunkEntity } from "../cmp/CmpChunkEntity";
import { CmpFood } from "../cmp/CmpFood";

/**
 * 食物创建
 */
export class FoodFactory {

    /**
     * 创建食物
     * @param scene 场景
     * @param pos 位置
     * @param score 分数
     * @param lifeTime 存活时间 -1 永久存活
     * @param color 十进制颜色 没有代表随机
     */
    static createFood(scene: ECSScene, pos: IVec2, score: number, lifeTime?: number, color?: number) {
        const entity = scene.createEntity();
        entity.pos.setPosTo(pos);
        const food = entity.createCmp(CmpFood).onCreate(score, lifeTime, color);
        entity.createCmp(CmpChunkEntity).onCreate(ChunkEntityType.food, ChunkEntityUpdateType.static, food.collider.worldAABB);
        entity.apply();
        return food;
    }

}